import tkinter as tk
import tkinter.messagebox
from tkinter import *
root = tk.Tk()
root.title("My First GUI")
root.geometry("400x400")
tk.Spinbox(root,from_=0,to=20,increment=2,width=15,bg='#9BCD9C').grid()
tk.Spinbox(root,values=("Python","Java","C语言","C++","PHP"),increment=2,width=15,bg='#9BCD9C').grid()
text = Text(root,width=20,height=5,bg='#9BCD9C',undo= True,autoseparators= False)
text.grid()
text.insert(INSERT,"Hello World,哇哦！很不错哟")
def backout ():
    text.edit_undo()
def regain():
    text.edit_redo()
Button(root,text="撤销",command=backout).grid(row=3,column=0,sticky=W,padx=10,pady=5)
Button(root,text="恢复",command=regain).grid(row=3,column=0,sticky=E,padx=10,pady=5)
def menuComand():
    tkinter.messagebox.showinfo("主菜单栏","您正在使用主菜单栏")
def func():
    print('您通过弹出菜单执行了命令')
def shortcut_new(event=None):
    tkinter.messagebox.showinfo('快捷键', '您按下了 Ctrl+N')

def shortcut_open(event=None):
    tkinter.messagebox.showinfo('快捷键', '您按下了 Ctrl+O')

def shortcut_print(event=None):
    tkinter.messagebox.showinfo('快捷键', '您按下了 Ctrl+P')

def shortcut_quit(event=None):
    tkinter.messagebox.showinfo('快捷键', '您按下了 Ctrl+Q')
main_menu = tk.Menu(root)
helpmenu = tk.Menu(main_menu,tearoff=False)
main_menu.add_cascade(label="文件",menu=helpmenu)
helpmenu.add_command(label="编辑",command=shortcut_new,accelerator="Ctrl+N")
helpmenu.add_command(label="格式",command=shortcut_open,accelerator="Ctrl+O")
helpmenu.add_command(label="查看",command=shortcut_print,accelerator="Ctrl+P")
helpmenu.add_command(label="帮助",command=shortcut_quit,accelerator="Ctrl+Q")
helpmenu.add_separator()
helpmenu.add_command(label="退出",command=root.quit)
menu=tk.Menu(root,tearoff=False)
menu.add_command(label="新建",command=func)
menu.add_command(label="复制",command=func)
menu.add_command(label="粘贴",command=func)
menu.add_command(label="剪切",command=func)
root.bind("<Control-N>",shortcut_new)
root.bind("<Control-n>",shortcut_new)
root.bind("<Control-O>",shortcut_open)
root.bind("<Control-o>",shortcut_open)
root.bind("<Control-P>",shortcut_print)
root.bind("<Control-p>",shortcut_print)
root.bind("<Control-Q>",shortcut_quit)
root.bind("<Control-q>",shortcut_quit)
def command(event):
    menu.post(event.x_root,event.y_root)
root.bind("<Button-3>",command)
root.config(menu=main_menu)
root.mainloop()